(define-module (emacs lsp)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix build-system emacs)
  #:use-module (gnu packages emacs-xyz)
  #:use-module (fiio meghanada)
  #:use-module (guix packages)
  #:use-module (guix git-download))

(define-public emacs-meghanada
  (package
   (name "emacs-meghanada")
   (version "1.2.0")
   (source
    (origin
     (method git-fetch)
     (uri (git-reference
           (url "https://github.com/mopemope/meghanada-emacs.git")
           (commit (string-append "v" version))))
     (file-name (git-file-name name version))
     (sha256
      (base32
       "1ripap7is2amk3i2mavwiiv5mfsx9k3gxpy9nyaz58pzgvyjqplc"))))
   (build-system emacs-build-system)
   (arguments
     `(#:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'configure
           (lambda* (#:key inputs #:allow-other-keys)

             (chmod "meghanada.el" #o644)
             (emacs-substitute-variables "meghanada.el"
               ("meghanada-server-install-dir"
                (string-append (assoc-ref inputs "meghanada-server") "/share")))
             #t)))))
   (propagated-inputs
    `(("emacs-yasnippet" ,emacs-yasnippet)
      ("emacs-company" ,emacs-company)
      ("emacs-flycheck" ,emacs-flycheck)))
   (inputs
    `(("meghanada-server" ,meghanada-server)))
   (home-page
    "https://github.com/mopemope/meghanada-emacs")
   (synopsis "A better java development mode")
   (description
    "Meghanada has a server component which can read the AST of your
project and its dependencies, providing features.")
   (license license:gpl3+)))
